package com.housekeeping.housekeeping.cleanerInformation.controller;

import com.housekeeping.housekeeping.cleanerInformation.service.ICleanerRestoreService;
import com.housekeeping.housekeeping.cleanerInformation.service.impl.CleanerRestoreServiceImpl;
import com.housekeeping.housekeeping.cleanerInformation.utils.ResponseEntity;
import com.housekeeping.housekeeping.cleanerInformation.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author hua
 * @version JDK1.8
 * @date 2021/1/24 22:10
 * 删除保洁员信息 根据id删除 前端只需要将保洁员的id 传过来
 */
@WebServlet("/cleanerInformation/controller/RestoreDeleteController")
public class RestoreDeleteController extends HttpServlet {
    private ICleanerRestoreService cleanerRestoreService = new CleanerRestoreServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置请求字符集
        request.setCharacterEncoding("utf-8");
        //设置响应字符集
        response.setContentType("text/html;charset=utf-8");

        int id = Integer.parseInt(request.getParameter("message"));

        ResponseEntity<Object> entity = null;

        int i = 0;
        try {
            i = cleanerRestoreService.cleanerRestoreDelete(id);
            if (i > 0){
                entity = ResponseEntity.success(null);
            }else {
                entity = ResponseEntity.error(405,"删除失败");
            }
        } catch (SQLException throwables) {
            entity = ResponseEntity.error(402,"网络异常,请稍后再试");
        }
        ResponseUtils.resp(response,entity);
    }
}
